package vip.specimen.system.datasource.validation.implement;

import vip.specimen.system.datasource.entity.SystemArticleTagsEntity;
import vip.specimen.system.datasource.validation.annotation.Tags;
import vip.specimen.system.service.SystemArticleTagsService;

import javax.annotation.Resource;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.List;
import java.util.Set;
import java.util.UUID;

/**
 * *@Author: 余浪人
 * *@Date：2021/4/12 10:19
 * *@Email:yulangren520@Gmail.com
 * *@QQ:1368419640
 **/
public class TagsImp implements ConstraintValidator<Tags, Set<UUID>> {
    @Resource
    private SystemArticleTagsService articleTagsService;

    @Override
    public boolean isValid(Set<UUID> uuidList, ConstraintValidatorContext constraintValidatorContext) {
        if (null == uuidList || uuidList.size() == 0) return true;
        List<SystemArticleTagsEntity> list = this.articleTagsService.findAllById(uuidList);
        return (uuidList.size() == list.size()) && !list.contains(null);
    }
}
